package enterprise.web.tookit.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

/**
 * @author Regis Rocha
 * 
 * @since 14/10/2012
 * 
 * @description Servlet implementation class Principal. any request to Principal send redirect to
 *              rest/principal.
 */
public class Principal extends HttpServlet {

	/**
	 * serial version
	 */
	private static final long serialVersionUID = 8867698703142598017L;

	/**
	 * LOG
	 */
	private static final Logger LOG = Logger.getLogger(Principal.class);

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public Principal() {
		super();
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		LOG.info("Logado com sucesso.");

		// set the webContext attribute to context web.
		req.getSession().setAttribute("webContext", req.getContextPath());

		final javax.servlet.RequestDispatcher view = req.getRequestDispatcher("/WEB-INF/pages/principal/principal.jsp");
		view.forward(req, resp);

		// resp.sendRedirect(req.getContextPath() + "/rest/principal");
	}
}
